package ru.spbau.database.group3.generator;

import java.io.IOException;
import java.util.Random;

/**
 * @author: Osipov Stanislav
 */
public class InsertQueryGenerator {
    public static String getNextInsertQuery() {
        String name = "\"" + elvenNameGenerator.compose(random.nextInt(3) + 2) + "\"";
        int age = random.nextInt(3000) + 20;
        int weight1 = random.nextInt(30) + 45;
        int weight2 = random.nextInt(10000);
        int height1 = random.nextInt(100) + 160;
        int height2 = random.nextInt(10000);
        String town =  "\"" + cityNameGenerator.compose(random.nextInt(3) + 2) + "\"";
        int orcs = random.nextInt(2353453);
        int fee1 = random.nextInt(925678257) + 100;
        int fee2 = random.nextInt(999999);
        int spells = random.nextInt(17245);
        return PREFIX + name + DEL + age +  DEL + weight1 + DOT + weight2 + DEL + height1 + DOT + height2 + DEL + town + DEL + orcs + DEL +
                fee1 + DOT + fee2 + DEL + spells + END;

    }

    private final static Random random = new Random();
    private static NameGenerator cityNameGenerator;
    private static NameGenerator elvenNameGenerator;

    static {
        try {
            cityNameGenerator = new NameGenerator("./res/cityNames.txt");
            elvenNameGenerator = new NameGenerator("./res/elvenNames.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static final String CREATE_QUERY = "CREATE TABLE elfTestTable(elfName VARCHAR(31), age INT, weight DOUBLE, height DOUBLE, hometown VARCHAR(34), orcsKilled INT, fee DOUBLE, spellsLearned INT)";

    public static final String CREATE_INDEX_QUERY = "CREATE INDEX ageCity ON elfTestTable(age, hometown) USING HASH";

    public static  final String SELECT_QUERY = "SELECT * FROM elfTestTable";

    public static final String PREFIX = "INSERT INTO " +
            "elfTestTable(elfName, age, weight, height, hometown, orcsKilled, fee, spellsLearned)" +
            " VALUES (";

    private static final String DEL = ",";
    private static final String DOT = ".";
    private static final String END = ")";

    public static void main(String[] args) {
        for(int i = 0; i < 10; ++i) {
            System.out.println(getNextInsertQuery());
        }
    }
}
